package com.example.demo.web.rest.controller;

import com.ffcs.oss.annotation.LogIgnore;
import com.ffcs.oss.annotation.PermissionAuth;
import com.example.demo.client.SmQryClient;
import com.example.demo.client.evt.cssmqry.user.QryUserEvt;
import com.example.demo.client.evt.sysbasequery.*;
import com.example.demo.client.vm.cssmqry.user.SimpleUserVm;
import com.example.demo.client.vm.sysbasequery.*;
import com.ffcs.oss.common.utils.LocalMessageUtil;
import com.example.demo.domain.ResourceEntity;
import com.example.demo.domain.SysbasePrimaryKey;
import com.example.demo.enums.*;
import com.example.demo.mapper.LogMapper;
import com.example.demo.mapper.SysbasePrimaryKeyMapper;
import com.example.demo.mapper.UserMapper;
import com.ffcs.oss.param.out.ServiceResp;
import com.ffcs.oss.param.vm.QueryPageVm;
import com.example.demo.security.AuthoritiesConstants;
import com.example.demo.security.SecurityUtils;
import com.example.demo.service.ExcelService;
import com.example.demo.service.UserService;
import com.example.demo.util.Coder;
import com.example.demo.util.PasswordUtils;
import com.example.demo.web.rest.constant.DatabaseConstant;
import com.example.demo.web.rest.constant.ExportConstant;
import com.example.demo.web.rest.evt.*;
import com.example.demo.web.rest.vm.BatchUserEvt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户管理
 *
 * @Author zmf
 * @Date 2018/12/12  18:13
 */
@Api("用户管理")
@RestController
@RequestMapping("/api/user")
public class UserController extends BaseController {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private SmQryClient csSmQrySrvClient;
    @Autowired
    private UserService userService;
    @Autowired
    private ExcelService excelService;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private LogMapper logMapper;
    @Autowired
    private SysbasePrimaryKeyMapper sysbasePrimaryKeyMapper;

    @ApiOperation(value = "清除项目缓存")
    @PostMapping("/clearQryCache")
    public ServiceResp clearQryCache() {
        return csSmQrySrvClient.clearQryCache();
    }

    @ApiOperation(value = "是否可以编辑用户", notes = "判断对应用户是否为超级管理员或是否为当前用户")
    @PostMapping("/isEditUser")
    public ServiceResp<Boolean> isEditUser(@RequestBody @Validated IsEditUserEvt evt) {
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.isEditUser(evt);
    }

    @ApiOperation(value = "重置密码")
    @PermissionAuth(code = "OSS-SETTING-USER-EDIT")
    @PostMapping("/resetPassword")
    public ServiceResp resetPassword(HttpServletRequest request, @RequestBody @Validated UserModifyEvt evt) {
        IsEditUserEvt isEditUserEvt = new IsEditUserEvt();
        BeanUtils.copyProperties(evt, isEditUserEvt);
        isEditUserEvt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        Boolean isEditUser = baseQueryClient.isEditUser(isEditUserEvt).getBody();
        if (isEditUser) {
            KeyEvt keyEvt = new KeyEvt(SysConfigEnum.RESET_PWD_VALUE.name());
            String pwd = baseQueryClient.getSystemConfigValueByKey(keyEvt).getBody();
            if (StringUtils.isBlank(pwd)) {
                pwd = SysConfigEnum.RESET_PWD_VALUE.getValue();
            }
            try {
                String password = userService.resetPassword(evt.getUserId(), pwd, evt.getUserName());
//                operateLogEvt.setOperateResultStatus("成功");
//                userService.saveResetPasswordLog(operateLogEvt);
                //添加操作日记
                savaMyOprateLog(request,"重置密码：" + evt.getUserName());
                return ServiceResp.getInstance(String.class).success("用户" + evt.getUserName() + "密码重置成功,重置密码为" + password, "");
            } catch (Exception e) {
                logger.error("重置密码异常", e);
//                operateLogEvt.setOperateResultStatus("失败");
//                userService.saveResetPasswordLog(operateLogEvt);
                return ServiceResp.getInstance().error("重置密码异常");
            }
        }
        return ServiceResp.getInstance().error("您无权重置该用户！");
    }

    public void savaMyOprateLog(HttpServletRequest request,String operateComment){
        //添加操作日记
        try {
            SaveOperateLogEvt operateLogEvt = new SaveOperateLogEvt();
            operateLogEvt.setModuleType("0");//菜单类型 - 0:页面
            operateLogEvt.setOperateAction("oss-setting-ui-userManage");
            operateLogEvt.setOperateComment(operateComment);
            operateLogEvt.setOperateResult(YesOrNo.Y.name());
            operateLogEvt.setCreateUserName(SecurityUtils.getCurrentUserLogin().get());
            operateLogEvt.setUpdateUserName(SecurityUtils.getCurrentUserLogin().get());
            operateLogEvt.setUpdateTime(new Date());
            operateLogEvt.setCreateTime(new Date());
            operateLogEvt.setIpAddress(com.ffcs.oss.utils.IpUtils.getIpAddress(request));
            //TableIdSizeEvt tableIdSizeEvt = new TableIdSizeEvt(DatabaseConstant.TABLE_NAME_OPERATE_LOG, DatabaseConstant.ID_SIZE);
            operateLogEvt.setId(getTableId(DatabaseConstant.TABLE_NAME_OPERATE_LOG,1));
            logger.info("保存日志ID{}",operateLogEvt.getId());
            logMapper.saveOperateLog(operateLogEvt);
        }catch (Exception e){
            logger.error("保存日志异常："+operateComment);
            logger.error("保存日记异常信息："+e.getMessage());
            e.printStackTrace();
        }
    }
    private final Integer maxSize=1000;
    public synchronized Long getTableId(String tblName,Integer size)
    {
        //获取表名
        String tableName = tblName.toUpperCase();
        if (size > maxSize) {
            size = maxSize;
        }
        logger.info("bizKey:{}", tableName);
        Long id;
        id = getIdFromTable(tableName,size);
        logger.info("为{}生成主键值->:{}", tableName, id);
        return id;
    }
    public long getIdFromTable(String tableName, int size) {
        long id;
        //查找该表名的那一条数据
        SysbasePrimaryKey sysbasePrimaryKey = sysbasePrimaryKeyMapper.getOne(tableName);
        long currentValue = 1;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        if (sysbasePrimaryKey == null) {
            //无数据往数据库插入一条并且currentValue给为1(对主键表进行操作)
            //获取配置表的最大id
            List<SysbasePrimaryKey> idList= sysbasePrimaryKeyMapper.getListOrderbyIdDesc();
            Long maxId = 0L;
            if(idList.size()!=0) {
                maxId = idList.get(0).getSysbasePrimaryKeyId();
            }
            sysbasePrimaryKey = new SysbasePrimaryKey();
            sysbasePrimaryKey.setCurrentValue((long) (1 + size));
            sysbasePrimaryKey.setEntityName(tableName);
            sysbasePrimaryKey.setLockTime(simpleDateFormat.format(new Date()));
            sysbasePrimaryKey.setSize(size);
            sysbasePrimaryKey.setSysbasePrimaryKeyId(maxId+1);
            sysbasePrimaryKeyMapper.save(sysbasePrimaryKey);
        } else {
            currentValue = sysbasePrimaryKey.getCurrentValue();
            //先更新表，因为没有事务，防止出现map中有值，数据库未更新情况
            sysbasePrimaryKey.setCurrentValue(currentValue+ size);
            sysbasePrimaryKeyMapper.updateByEntityNameAndLockTime(sysbasePrimaryKey,simpleDateFormat.format(new Date()));

        }
        id = currentValue;
        return id;
    }


    /*@ApiOperation(value = "禁用/锁定用户")
    @PostMapping("/disableUser")
    public ServiceResp disableUser(@RequestBody @Validated UserModifyEvt evt){
        IsEditUserEvt isEditUserEvt = new IsEditUserEvt();
        BeanUtils.copyProperties(evt,isEditUserEvt);
        isEditUserEvt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        Boolean isEditUser = baseQueryClient.isEditUser(isEditUserEvt).getBody();
        if(isEditUser){
            userService.updateStatus(3,evt.getUserId());
            return ServiceResp.getInstance(String.class).success("禁用成功!","");
        }
        return ServiceResp.getInstance().error("您无权禁用该用户！");
    }

    @ApiOperation(value = "启用/解锁用户")
    @PostMapping("/enableUser")
    public ServiceResp enableUser(@RequestBody @Validated UserModifyEvt evt){
        IsEditUserEvt isEditUserEvt = new IsEditUserEvt();
        BeanUtils.copyProperties(evt,isEditUserEvt);
        isEditUserEvt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        Boolean isEditUser = baseQueryClient.isEditUser(isEditUserEvt).getBody();
        if(isEditUser){
            userService.updateStatusAndPasswordUpdateDate(1,evt.getUserId());
            */

    /**
     * 启用的时候删除掉登陆密码错误过多次被禁用的记录
     *//*
            return ServiceResp.getInstance(String.class).success("启用成功!","");
        }
        return ServiceResp.getInstance(String.class).error("您无权启用该用户！");
    }*/
    @ApiOperation(value = "批量操作用户")
    @PermissionAuth(code = "OSS-SETTING-USER-EDIT")
    @PostMapping("/batchUser")
    public ServiceResp batchUser(HttpServletRequest request,@RequestBody @Validated BatchUserEvt evt) {
        //添加逻辑判断,批量通过，
        String msg = userService.batchUser(evt);
        String loginName = SecurityUtils.getCurrentUserLogin().get();
        //操作用户名
        String allUsers = "";
        //操作名称
        String actionName = "";
        for (UserModifyEvt umEvt :
                evt.getUserModifyList()) {
            IsEditUserEvt isEditUserEvt = new IsEditUserEvt();
            BeanUtils.copyProperties(umEvt, isEditUserEvt);
            isEditUserEvt.setLoginName(loginName);
            Boolean isEditUser = baseQueryClient.isEditUser(isEditUserEvt).getBody();
            if (!isEditUser) {
                return ServiceResp.getInstance(String.class).error("您无权操作" + umEvt.getUserName() + "用户！");
            }
            allUsers = allUsers.equals("") ? umEvt.getUserName() : allUsers + "," + umEvt.getUserName();
        }
        try {
            if (evt.getOperation().equals(UserStatus.USER_CANCEL.getValue())) {
                for (UserModifyEvt umEvt :
                        evt.getUserModifyList()) {
                    userService.delUser(umEvt.getUserId());
                }
                actionName = "注销用户：";
            } else {
                for (UserModifyEvt umEvt :
                        evt.getUserModifyList()) {
                    userService.updateStatusMapper(evt.getOperation(), umEvt.getUserId());
                }
                actionName = "更新用户状态：";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ServiceResp.getInstance(String.class).error(e.getMessage());
        }
        baseQueryClient.clearUserCache();
        //添加操作日记
        if(StringUtils.isBlank(msg)){
            actionName = actionName+allUsers;
        }else{
            actionName = actionName+allUsers+";其中" + msg + "不允许进行此操作";
        }
        savaMyOprateLog(request,actionName);
        if (StringUtils.isBlank(msg)) {
            return ServiceResp.getInstance(String.class).success("批量操作成功!", "");
        } else {
            return ServiceResp.getInstance(String.class).success("批量操作成功!,其中" + msg + "不允许进行此操作", "");
        }

    }

    /*@ApiOperation(value = "删除用户")
    @PostMapping("/deleteUser")
    public ServiceResp deleteUser(@RequestBody @Validated UserModifyEvt evt){
        IsEditUserEvt isEditUserEvt = new IsEditUserEvt();
        BeanUtils.copyProperties(evt,isEditUserEvt);
        isEditUserEvt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        //判断选中用户是否为超级管理员或为当前用户(不能编辑自己)
        Boolean isEditUser = baseQueryClient.isEditUser(isEditUserEvt).getBody();
        if(isEditUser){
            userService.delUser(evt.getUserId());
            return ServiceResp.getInstance(String.class).success("注销成功!","");
        }
        return ServiceResp.getInstance().error("您无权删除该用户！");
    }*/

    @ApiOperation(value = "保存用户")
    @PermissionAuth(code = "OSS-SETTING-USER-EDIT,OSS-SETTING-USER-ADD")
    @PostMapping("/saveUser")
    public ServiceResp saveUser(HttpServletRequest request,@RequestBody SaveUserEvt evt) {
        try {
            IsEditUserEvt isEditUserEvt = new IsEditUserEvt();
            isEditUserEvt.setUserName(evt.getUserInfo().getLoginName());
            isEditUserEvt.setUserType(evt.getUserInfo().getUserType());
            isEditUserEvt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
            Boolean isEditUser = baseQueryClient.isEditUser(isEditUserEvt).getBody();
            if (!isEditUser) {
                return ServiceResp.getInstance(String.class).error("您无权操作该用户！");
            }
            userService.saveUser(evt);
            baseQueryClient.clearQryCache();
            //添加操作日记
            savaMyOprateLog(request,"保存用户信息：" + evt.getUserInfo().getLoginName());
            return ServiceResp.getInstance(Boolean.class).success(true);
        } catch (Exception e) {
            logger.error("保存用户异常", e);
            e.printStackTrace();
            return ServiceResp.getInstance().error(e.getMessage());
        }
    }

    @ApiOperation(value = "批量修改用户权限")
    @PermissionAuth(code = "OSS-SETTING-USER-EDIT")
    @PostMapping("/saveBatchUserPermissions")
    public ServiceResp<Boolean> saveBatchUserPermissions(@RequestBody @Validated SaveBatchUserPermissionEvt evt) {
        userService.saveBatchUserPermissions(evt);
        return ServiceResp.getInstance(Boolean.class).success(true);
    }

    @ApiOperation(value = "判断当前用户是否超级管理员")
    @PostMapping("/isAdmin")
    public ServiceResp<Boolean> isAdmin() {
        return ServiceResp.getInstance(Boolean.class).success(SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN));
    }


    @ApiOperation(value = "判断密码强度是否符合强度要求")
    @PostMapping("/isPwdStrong")
    public ServiceResp<Boolean> isPwdStrong(@RequestBody @Validated PwdEvt evt) {
        KeyEvt keyEvt = new KeyEvt(SysConfigEnum.IS_WEAK_PWD_VERIFY.name());
        String isWeakPwd = baseQueryClient.getSystemConfigValueByKey(keyEvt).getBody();
        if (isWeakPwd != null && isWeakPwd.equals(SysConfigEnum.IS_WEAK_PWD_VERIFY.getValue())) {
            if (!PasswordUtils.isPasswordStrong(evt.getPassword())) {
                return ServiceResp.getInstance(Boolean.class)
                        .success(false, "密码强度不符合要求，长度至少8位且必须包括数字、小写字母、大写字母和特殊符号4类！");
            }
        }
        return ServiceResp.getInstance(Boolean.class)
                .success(true, "密码强度验证通过！");
    }

    @ApiOperation("用户名是否存在")
    @PostMapping("/isUserNameExist")
    public ServiceResp<Boolean> isUserNameExist(@RequestBody @Validated IsUserNameExistEvt evt) {
        return baseQueryClient.isUserNameExist(evt);
    }

    @ApiOperation("用户管理获取角色树")
    @PostMapping("/getRoleTree")
    public ServiceResp<List<RoleTreeVm>> getRoleTree(@RequestBody UserIdEvt evt) {
        evt.setLoginName("admin");
        return baseQueryClient.getRoleTreeOfUser(evt);
    }

    @ApiOperation("用户管理功能权限树")
    @PostMapping("/getPermissionTree")
    public ServiceResp<List<PermissionTreeVm>> getPermissionTree(@RequestBody UserIdEvt evt) {
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.getPermissionTree(evt);
    }

    @ApiOperation("用户管理批量赋权树")
    @PostMapping("/getBatchPermissionTree")
    public ServiceResp<List<PermissionTreeVm>> getBatchPermissionTree(@RequestBody @Validated UserIdsEvt evt) {
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.getBatchPermissionTree(evt);
    }

    @ApiOperation("用户管理下拉框取数接口")
    @PostMapping("/getUserStaticData")
    public ServiceResp<UserStaticDataVm> getUserStaticData() {
        return baseQueryClient.getUserStaticData();
    }

    @ApiOperation("查询用户信息")
    @PostMapping("/queryUser")
    public ServiceResp<QueryPageVm<QueryUserVm>> queryUser(@RequestBody QueryUserEvt evt) {
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.queryUser(evt);
    }

    /*@ApiOperation("查询用户信息")
    @PostMapping("/queryUser")
    public ServiceResp<QueryPageVm> queryUser(@RequestBody QueryUserEvt evt){
        return ServiceResp.getInstance(QueryPageVm.class).success(userService.queryUser(evt));
    }*/

    @ApiOperation("根据ID获取用户信息")
    @PostMapping("/getUserById")
    public ServiceResp<UserVm> getUserById(@RequestBody @Validated UserIdEvt evt) {
        return baseQueryClient.getUserById(evt);
    }

    @ApiOperation("查询登录用户信息")
    @PostMapping("/getLoginUserInfo")
    public ServiceResp getLoginUserInfo() {
        QueryUserVm vm = userService.getLoginUserInfo();
        if (vm != null) {
            return ServiceResp.getInstance().success(vm);
        } else {
            return ServiceResp.getInstance().error("用户信息异常");
        }
    }

    @ApiOperation("用户管理资源权限树")
    @PostMapping("/getResourceTree")
    public ServiceResp<List<ResourceEntity>> getResourceTreeOfUser(@RequestBody ResourceTreeOfUserEvt evt) {
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.getResourceTreeOfUser(evt);
    }

    @ApiOperation("获取用户组树")
    @PostMapping("/getUserGroupTree")
    public ServiceResp<List<UserGroupTreeVm>> getUserGroupTree(@RequestBody UserGroupTreeEvt evt) {
        evt.setAdmin(SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN));
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.getGroupTreeOfUser(evt);
    }

    @ApiOperation("获取区域信息-用户管理")
    @PostMapping("/getRegionTree")
    public ServiceResp<List<QueryRegionListVm>> getRegionTree() {
        LoginNameEvt evt = new LoginNameEvt();
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.getRegionTree(evt);
    }

    @ApiOperation("修改密码")
    @PermissionAuth(code = "OSS-SETTING-USER-EDIT")
    @PostMapping("/savePasswd")
    public ServiceResp savePasswd(@RequestBody(required = true) @Validated ModifyPwdEvt modifyPwdEvt, HttpServletRequest request) throws Exception {
        logger.debug("类名【{}】函数名【{}】入参信息【{}】", "ModifyPwdController", "savePasswd", modifyPwdEvt.toString());
        String name = SecurityUtils.getCurrentUserLogin().get();
        if (org.apache.commons.lang.StringUtils.isBlank(modifyPwdEvt.getOldPwd())) {
            return ServiceResp.getInstance().error("旧密码为空");
        }
        if (org.apache.commons.lang.StringUtils.isBlank(modifyPwdEvt.getNewPwd())) {
            return ServiceResp.getInstance().error("新密码为空");
        }
        if (modifyPwdEvt.getOldPwd().equals(modifyPwdEvt.getNewPwd())) {
            return ServiceResp.getInstance().error("新密码不能与旧密码相同");
        }
        try {
            modifyPwdEvt.setOldPwd(Coder.encryptMD5(modifyPwdEvt.getOldPwd() + name));
            modifyPwdEvt.setNewPwd(Coder.encryptMD5(modifyPwdEvt.getNewPwd() + name));
        } catch (Exception e) {
            return ServiceResp.getInstance().error("系统错误-请与管理员联系");
        }
        QryUserEvt loginNameEvt = new QryUserEvt();
        loginNameEvt.setLoginName(name);
        SimpleUserVm loginUserInfo = csSmQrySrvClient.qrySimpleUser(loginNameEvt).getBody();
        //1.判断旧密码是否与当前登录用户的旧密码相同
        if (!modifyPwdEvt.getOldPwd().equals(loginUserInfo.getPassword())) {
            return ServiceResp.getInstance().error("旧密码错误");
        }
        //获取最近可以重复使用同一个密码次数
        String value = csSmQrySrvClient.getSystemConfigValueByKey(new KeyEvt(SysConfigEnum.PASSWORD_MODIFY_TIMES.name())).getBody();
        int countNum = 0;
        if (org.apache.commons.lang.StringUtils.isNotBlank(value)) {
            countNum = Integer.parseInt(value);
        }
        int count = countNum;
        String pwdInfo = "";
        //查询用户近期使用的五个密码
        Long userId = loginUserInfo.getUserId();
        List<String> usedPwdList = userService.getNearlyFivePwd(userId);
        if (usedPwdList != null && usedPwdList.size() > 0) {
            if (usedPwdList.size() < countNum) {
                count = usedPwdList.size();
            }
            for (int i = 0; i < count; i++) {
                pwdInfo = usedPwdList.get(i);
                if (pwdInfo.equals(modifyPwdEvt.getNewPwd())) {
                    //n次内已使用该密码
                    return ServiceResp.getInstance().error(countNum + "次内已使用该密码,请重新设置密码");
                }
            }
        }
        //保存用户的密码修改信息
        userService.saveUserPwdInfo(userId, modifyPwdEvt.getNewPwd());
        logger.info("savePasswd->密码修改成功");
        List<Long> allUserId = new ArrayList<>();
        allUserId.add(userId);
        userMapper.updateMustUpdStatus(allUserId, YesOrNo.N.getValue());
        return ServiceResp.getInstance(String.class).success("密码修改成功", "");
    }

    @ApiOperation("导出用户列表")
    @PermissionAuth(code = "OSS-SETTING-USER-EXPORT")
    @GetMapping("/exportUser")
    public void exportUser(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "paramStr") String paramStr) throws Exception {
        try {
            String exportFileName = LocalMessageUtil.getMessage(ExportConstant.EXPORT_USER_MANAGE) + ExportConstant.EXPORT_FILE_FORMAT;
            excelService.exportExcel(request, response, ExportListEnum.USER.getExpColEn(), ExportListEnum.USER.getExpColCn(),
                    exportFileName, LocalMessageUtil.getMessage(ExportConstant.EXPORT_USER_MANAGE), ExportListEnum.USER.getValue(), paramStr);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    @ApiOperation(value = "下载用户导入模板")
    @PermissionAuth(code = "OSS-SETTING-USER-IMPORT")
    @GetMapping("/downloadUserModel")
    public void downloadUserModel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String exportFileName = LocalMessageUtil.getMessage(ExportConstant.EXPORT_USER_MANAGE + ExportConstant.EXPORT_TEMPLATE)
                + ExportConstant.EXPORT_FILE_FORMAT;
        excelService.downloadModel(request, response, exportFileName);
    }

    @ApiOperation("导入用户")
    @PermissionAuth(code = "OSS-SETTING-USER-IMPORT")
    @PostMapping("/ImportUserData")
    @LogIgnore
    public ServiceResp ImportUserData(MultipartFile file) {
        return excelService.importData(file, ImportEnum.USER, ImportEnum.USER_NOT_NULL);
    }


    @ApiOperation("获取组织树携带用户数据")
    @PostMapping("/getGroupUser")
    public ServiceResp getGroupUser(@RequestBody UserGroupTreeEvt evt) {
        evt.setAdmin(SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN));
        evt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
        return baseQueryClient.getGroupUser(evt);
    }


}
